package com.syl.practice.xml;
import	java.io.BufferedReader;

import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class XmlPra {
    public static void main(String[] args) {
        loadXml1();
        loadXml2();
    }

    public static void loadXml1(){
        try {
            Properties properties = new Properties();
            // 绝对路径
            BufferedReader bufferedReader = new BufferedReader(new FileReader("D:\\ideaNode\\newpractice\\src\\resources\\test.properties"));
            properties.load(bufferedReader);
            System.out.println(properties.getProperty("name"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void loadXml2(){
        try {
            Properties properties = new Properties();
            // 相对路径
            InputStream in = XmlPra.class.getClassLoader().getResourceAsStream("test.properties");
            // 使用properties对象加载输入流
            properties.load(in);
            //获取key对应的value值
            System.out.println(properties.getProperty("name"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
